/*
 * FXGL - JavaFX Game Library. The MIT License (MIT).
 * Copyright (c) AlmasB (almaslvl@gmail.com).
 * See LICENSE for details.
 */

package com.windea.study.kotlin.fxgl.sample.sandbox

import com.almasb.fxgl.app.*
import com.almasb.fxgl.core.math.*
import com.almasb.fxgl.dsl.*
import javafx.concurrent.*
import javafx.scene.paint.*
import javafx.scene.shape.*

/**
 * This is an example of a minimalistic FXGL game application.
 *
 * @author Almas Baimagambetov (AlmasB) (almaslvl@gmail.com)
 */
class LoadingSample : GameApplication() {
	override fun initSettings(settings: GameSettings) {
		settings.width = 800
		settings.height = 600
		settings.title = "LoadingSample"
		settings.version = "0.1"
		settings.isIntroEnabled = false
		settings.isMenuEnabled = true
		settings.sceneFactory = object : SceneFactory() {
			override fun newLoadingScene(): LoadingScene {
				return MyLoadingScene()
			}
		}
	}
	
	override fun initGame() {
		try {
			Thread.sleep(4000)
		} catch(e: InterruptedException) {
			e.printStackTrace()
		}
		
	}
	
	override fun initUI() {
		try {
			Thread.sleep(4000)
		} catch(e: InterruptedException) {
			e.printStackTrace()
		}
		
	}
	
	inner class MyLoadingScene : LoadingScene() {
		
		private val r = Rectangle(40.0, 0.0, null)
		
		init {
			
			contentRoot.children.clear()
			
			r.stroke = Color.BLACK
			
			r.translateX = FXGLMath.random(0, FXGL.getAppWidth()).toDouble()
			r.translateY = FXGLMath.random(0, 2).toDouble()
			
			
			
			contentRoot.children.addAll(r)
		}
		
		override fun bind(task: Task<*>) {
			task.progressProperty().addListener { observable, oldValue, progress -> r.height = FXGL.getAppHeight() * progress.toDouble() }
		}
		
	}
}


fun main(args: Array<String>) {
	GameApplication.launch(LoadingSample::class.java, args)
}
